@RestController
@RequestMapping("/api/playlist-ratings")
public class PlaylistRatingController {
    @Autowired
    private PlaylistRatingService playlistRatingService;

    @PostMapping("/rate")
    public ResponseEntity<?> ratePlaylist(@RequestBody PlaylistRatingRequest ratingRequest) {
        Long userId = ratingRequest.getUserId();
        Long playlistId = ratingRequest.getPlaylistId();
        int rating = ratingRequest.getRating();

        PlaylistRating savedRating = playlistRatingService.ratePlaylist(userId, playlistId, rating);
        if (savedRating != null) {
            return ResponseEntity.ok(savedRating);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("评分失败");
        }
    }
}
